// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   PriceLimit.java

package include.auto_execute;

import include.nseer_db.nseer_db_backup;
import java.io.PrintStream;
import java.sql.ResultSet;
import javax.servlet.ServletContext;

public class PriceLimit
{

	private nseer_db_backup nseer_db;
	private nseer_db_backup nseer_db1;
	private ResultSet rs;

	public PriceLimit()
	{
		rs = null;
	}

	public void price(ServletContext dbApplication)
	{
		try
		{
			nseer_db_backup db = new nseer_db_backup(dbApplication);
			if (db.conn("mysql"))
			{
				String sqldb = "show databases";
				for (ResultSet rsdb = db.executeQuery(sqldb); rsdb.next();)
					if (rsdb.getString("database").equals("ondemand1"))
					{
						nseer_db = new nseer_db_backup(dbApplication);
						nseer_db1 = new nseer_db_backup(dbApplication);
						if (nseer_db.conn(rsdb.getString("database")) && nseer_db1.conn(rsdb.getString("database")))
						{
							String sql3 = "update design_file set price_alarm_tag='0'";
							nseer_db.executeUpdate(sql3);
							String sql4 = "select * from design_config_public_char where kind='priceAlarm'";
							ResultSet rs4 = nseer_db.executeQuery(sql4);
							double rate = 0.0D;
							if (rs4.next())
								rate = Double.parseDouble(rs4.getString("type_name")) / 100D;
							String sql = "select * from design_file where check_tag='1'";
							for (rs = nseer_db1.executeQuery(sql); rs.next();)
							{
								double price_odds = rs.getDouble("cost_price") - rs.getDouble("real_cost_price");
								if (Math.abs(price_odds / rs.getDouble("cost_price")) >= rate)
								{
									String sql2 = (new StringBuilder("update design_file set price_alarm_tag='1' where id='")).append(rs.getString("id")).append("'").toString();
									nseer_db.executeUpdate(sql2);
								}
							}

							nseer_db.close();
							nseer_db1.close();
						} else
						{
							System.out.println("i am sorry!");
						}
					}

				db.close();
			} else
			{
				System.out.println("i am sorry!");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
